package common.customer.service;

import java.util.List;

import common.customer.bean.Collect;
import common.customer.dao.CollectDao;

public class CollectServiceImpl implements CollectService {
	private CollectDao collectDao;
	@Override
	public boolean testExistCollect(int customerId,int keyId, String type) {
		String queryStr = "select count(c) from common.customer.bean.Collect c where c.keyId="+keyId +" and c.type='"+type+"' and c.user.id="+customerId;
		if((Long)this.collectDao.find(queryStr, true).get(0)>0){
			return true;
		}
		else{			
			return false;
		}
	}
	@Override
	public List<Collect> getCollectByCustomerId(int customerId, int page,
			int pageSize) {
		String queryStr = "from common.customer.bean.Collect c where c.user.id="+customerId;
		return this.collectDao.find(queryStr, page, pageSize);
	}
	@Override
	public long getCollectCountByCustomerId(int customerId) {
		String queryStr = " select count(c) from common.customer.bean.Collect c where c.user.id="+customerId;
		long result = (Long)this.collectDao.find(queryStr, true).get(0);
		return result;
	}
	@Override
	public boolean addCollect(Collect collect) {
		int result = this.collectDao.save(collect);
		if(result>0){
			return true;
		}else{			
			return false;
		}
	}

	@Override
	public boolean removeCollect(int cullectId) {
		Collect c = this.collectDao.get(cullectId);
		this.collectDao.delete(c);
		return true;
	}

	
	//===================getter and setter method=========================
	public CollectDao getCollectDao() {
		return collectDao;
	}
	public void setCollectDao(CollectDao collectDao) {
		this.collectDao = collectDao;
	}
}
